package other {
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	[Bindable]
	public class SWFLibraryManager extends EventDispatcher {
		
		
		public static const ASSETS_LOADED:String = 'assetsLoaded';
		
		private static var _instance:SWFLibraryManager;
		
		public var skinLoader:Loader;
		private var skin:MovieClip;
		
		private var _callback:Function = null;
		
		public var swfBytes:Class;
		public function SWFLibraryManager() {
			_instance = this;	
		}
		
		
		public static function getInstance():SWFLibraryManager {
			if (_instance == null) {
				_instance = new SWFLibraryManager();
			}
			
			return _instance;
		}
		
		
		//The load function will require the embed swf class		
		public function load(clazz:*, callback:Function):void {
			_callback = callback;
			
			skinLoader = new Loader();
			skinLoader.loadBytes(clazz);
			skinLoader.contentLoaderInfo.addEventListener(Event.INIT,onSkinLoaded);
		}
		
		
		public function getFlashInstance(name:String):Sprite {
			var SymbolClass:Class = skinLoader.contentLoaderInfo.applicationDomain.getDefinition(name) as Class;
			var symbolInstance:Sprite = new SymbolClass() as Sprite;
			
			return symbolInstance;
		}
		
		
		private function onSkinLoaded(event:Event):void {
			_callback();
		}
		
		
		
	}
}